package com.webserver.core;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class WebServerApplication {
    ServerSocket serverSocket;

    public WebServerApplication(){
        try {
            System.out.println("正在启动服务器....");
            serverSocket = new ServerSocket(8088);
            System.out.println("启动服务器成功");
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    public void start(){
        try {
            while (true){
                System.out.println("正在等待客户端连接.....");
                Socket socket = serverSocket.accept();
                System.out.println("客户端连接成功!");

                ClientHandler handler = new ClientHandler(socket);
                Thread t = new Thread(handler);
                t.start();
            }

        }catch (IOException e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        WebServerApplication application = new WebServerApplication();
        application.start();
    }
}
